package com.mxsat.system.dao.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mxsat.common.dao.DaoImpl;
import com.mxsat.system.dao.SysUserDao;
import com.mxsat.system.entity.SysUser;
import com.mxsat.system.mapper.SysUserMapper;

@Repository
public class SysUserDaoImpl extends DaoImpl<BaseMapper<SysUser>, SysUser> implements SysUserDao {

	@Autowired
	private SysUserMapper sysUserMapper;
	
	@Override
	public IPage<SysUser> selectUserByPage(IPage<SysUser> page, Map<String, Object> condition) throws Exception {
		QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
		if(!StringUtils.isEmpty(condition.get("keyword"))) {
			queryWrapper.like("name", condition.get("keyword"));
		}
		return this.page(page, queryWrapper);
	}

	@Override
	public SysUser selectUserByNameAndPwd(String name, String pwd) throws Exception {
		QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
		wrapper.eq("name", name).eq("pwd", pwd);
		return this.getOne(wrapper);
	}

	@Override
	public SysUser selectUserByName(String name) throws Exception {
		return sysUserMapper.selectUserByName(name);
	}

}
